using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class InvestmentSecuritySerieMap : EntityTypeConfiguration<InvestmentSecuritySerie>
    {
        public InvestmentSecuritySerieMap()
        {
            // Primary Key
            this.HasKey(t => new { t.InvestmentId, t.Date, t.SecurityId });

            // Properties
            this.Property(t => t.InvestmentId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.SecurityId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.AgeByTimeSeries)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("InvestmentSecuritySerie", "Analytics");
            this.Property(t => t.InvestmentId).HasColumnName("InvestmentId");
            this.Property(t => t.SecurityId).HasColumnName("SecurityId");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.AgeByTimeSeries).HasColumnName("AgeByTimeSeries");
            this.Property(t => t.MarketCapSum).HasColumnName("MarketCapSum");
            this.Property(t => t.Weight).HasColumnName("Weight").HasPrecision(29, 20);
            this.Property(t => t.Risk).HasColumnName("Risk").HasPrecision(29, 20);
            this.Property(t => t.RoC).HasColumnName("RoC").HasPrecision(29, 20);
            this.Property(t => t.CloseQuantity).HasColumnName("CloseQuantity");
            this.Property(t => t.CloseExposure).HasColumnName("CloseExposure");
            this.Property(t => t.PositionPnL).HasColumnName("PositionPnL");
            this.Property(t => t.PositionFxPnL).HasColumnName("PositionFxPnL");
            this.Property(t => t.TradePnL).HasColumnName("TradePnL");
            this.Property(t => t.TradeFxPnL).HasColumnName("TradeFxPnL");

            this.HasRequired(t => t.Security);
            
            this.HasRequired(t => t.Investment)
                .WithMany(t => t.SecuritySeries)
                .HasForeignKey(d => d.InvestmentId);
        }
    }
}
